package com.codinghero.example.jdk.proxy;

import java.lang.reflect.InvocationHandler;

import java.lang.reflect.Method;

import java.lang.reflect.Proxy;

public class ProxyImpl implements InvocationHandler {

	Object realObj;

	public ProxyImpl(Object obj) {
		this.realObj = obj;
	}

	public Object getProxyObj() {
		return Proxy.newProxyInstance(realObj.getClass().getClassLoader(),
				new Class[] { NumOper.class }, this);
	}

	// 实际代理类的方法执行通过调用此函数实现
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		System.out.println("before");
		Thread.sleep(100);
		Object obj = method.invoke(this.realObj, args);
		Thread.sleep(100);
		System.out.println("end");
		return obj;
	}

}